package boidAlgorithms.math;

import android.graphics.PointF;

public class Vector2D extends PointF {

	public Vector2D(float x, float y) {
		super(x, y);
	}

	public Vector2D(PointF target) {
		super(target.x,target.y);
	}

	public float getModule() {
		return length();
	}

	public float getAngle() {
		return (float) Math.atan2(y, x);
	}

	public Vector2D getUnitVector() {
		return new Vector2D(x / getModule(), y / getModule());
	}

	public void addWith(Vector2D b) {
		x = x + b.x;
		y = y + b.y;
	}

	public static Vector2D add(Vector2D a, Vector2D b) {
		return new Vector2D(a.x + b.x, a.y + b.y);
	}

	public static Vector2D getSubtraction(Vector2D a, Vector2D b) {
		return new Vector2D(a.x- b.x, a.y - b.y);
	}

	public void trim(float maxLenght) {
		float temp = getModule() / maxLenght;
		x = x / temp;
		y = y / temp;
	}

	public Vector2D getNormal() {
		return new Vector2D(-y, x);
	}

	public void truncate(float max){
		if (this.length()>max){
			Vector2D t=this.getUnitVector();
			t.multiplyWith(max);
			this.x=t.x;
			this.y=t.y;
		}
		
	}

	public Vector2D getSubtractionWith(Vector2D a) {
			return new Vector2D(this.x- a.x, this.y - a.y);
	}

	public void normalize() {
		this.x= x/getModule();
		this.y= y/getModule();
	}
	public void multiplyWith(float a){
		this.x= x*a;
		this.y= y*a;
	}

	public void setSizeTo(float max) {
		// TODO Auto-generated method stub
		normalize();
		multiplyWith(max);
	}
}
